﻿using DongRuanMachineWebService.XmlMapper;
using Entity.Utils;
using EntityLibrary.Business.AccountProcess;
using EntityLibrary.Business.AccountProcess.Entity;
using EntityLibrary.Business.BasicInfo;
using EntityLibrary.Business.BasicInfo.Entity;
using EntityLibrary.Business.ClinicAndPay;
using EntityLibrary.Business.ClinicAndPay.Entity;
using EntityLibrary.Business.RegistProcess;
using EntityLibrary.Business.RegistProcess.Entity;
using EntityLibrary.Business.ReportInfo;
using EntityLibrary.Business.ReportInfo.Entity;
using EntityLibrary.DomainCheck;
using EntityLibrary.Utils;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System.Xml.Serialization;
namespace DongRuanMachineWebService
{
    /// <summary>
    /// UniversalInterface 德宏州中医院东软一体机WebService
    /// </summary>
    [WebService(Namespace = "http://service.server.yardman.si.sl.neusoft.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class UniversalInterface : WebService
    {
        #region 字典及其它
        ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        //0：女 1：男 3：未知
        private readonly string[] SEX_TYPE = new string[3] { "0", "1", "3" };
        //1：就诊卡 2：社保卡 3：居民健康卡 4：身份证 5：银行卡 6：PatientId （目前仅支持4,6即身份证号，病人Id号登录）
        private readonly string[] cardType = new string[6] { "1", "2", "3", "4", "5", "6" };
        //支付方式: 0:无支付，1：现金支付 2：银联卡：3.微信 4：支付宝 5：翼支付 6：院内账户支付 7：医保结算
        private readonly string[] payTypeDic = new string[7] { "1", "2", "3", "4", "5", "6", "7" };
        private readonly Dictionary<int, string> PayTypeKeyValue = new Dictionary<int, string> { {0,"无支付"}
                                                                                                ,{1,"现金支付"}
                                                                                                ,{2,"银联卡"}
                                                                                                ,{3,"微信"}
                                                                                                ,{4,"支付宝"}
                                                                                                ,{5,"翼支付"}
                                                                                                ,{6,"院内账户支付"}
                                                                                                ,{7,"医保结算" } };
        //是否包含医保支付: false:不包含 true：包含
        private readonly string[] isMedicarePayDic = new string[2] { "true", "false" };
        //查询类别 1:未缴费,2:已缴费
        private readonly string[] queryTypeDic = new string[2] { "1", "2" };
        //费用编号类型 1:门诊流水号 2:处方编号 3:挂号编号 4: 预约挂号编号
        private readonly string[] feeNumberTypeDic = new string[4] { "1", "2", "3", "4" };
        //打印状态 0:未打印 1:已经打印 2:全部（作为查询条件可以使用）
        private readonly string[] printStatusDic = new string[3] { "0", "1", "2" };
        //收费类别 1：中成药 2：西成药 3：检验检查 4：中草药
        private readonly string[] feesItemDic = new string[4] { "1", "2", "3", "4" };

        //获取东软在服务段设定的组织机构代码
        private int callNo_DongRuan = CallNoType.CallNos.Values.ElementAt(Convert.ToInt32(CallNoIndex.DongRuan));
        private string callName_DongRuan = CallNoType.CallNos.Keys.ElementAt(Convert.ToInt32(CallNoIndex.DongRuan));
        //账户处理
        AccountProcessService accountService = new AccountProcessService();
        //挂号处理
        RegistProcessService registService = new RegistProcessService();
        //支付处理
        ClinicAndPayService clinicService = new ClinicAndPayService();
        //报告处理
        ReportService reportService = new ReportService();
        //基本信息
        BasicInfoService basicService = new BasicInfoService();
        #endregion

        /// <summary>
        /// 业务交易服务接口
        /// </summary>
        /// <param name="arg0">clientNode 客户端标识</param>
        /// <param name="arg1">buzzNumb 交易业务编码</param>
        /// <param name="arg2">version 交易版本号</param>
        /// <param name="arg3">transactionId 交易跟踪流水号</param>
        /// <param name="arg4">operatorName 操作员姓名</param>
        /// <param name="arg5">content 交易报文内容</param>
        /// <returns></returns>
        [WebMethod]
        [return: XmlElement("return")]
        public string send(string arg0, string arg1, string arg2, string arg3, string arg4, string arg5)
        {
            #region send 方法公共处理


            log.Info(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "入参:arg0" + arg0 + " arg1:" + arg1 + " arg2:" + arg2 + " arg3:" + arg3 + " arg4:" + arg4 + " arg5:" + arg5);
            //入参
            XmlDocument inputXMLdoc = new XmlDocument();
            inputXMLdoc.LoadXml(arg5.Trim());
            //返回值映射
            XMLMapper outputXML = new XMLMapper();
            CommonHead head = new CommonHead();
            CommonBody body = new CommonBody();
            outputXML.Head = head;
            head.Fun = arg1;
            head.Version = "1.0";
            head.Code = "1";
            string errorMessage = string.Empty;
            #endregion

            try
            {
                switch (arg1)
                {
                    #region 办理就诊卡
                    case "HIS_ATM_02120":
                        //姓名
                        inputXMLdoc.Check("request/body/patient/name", false, out var name02120);
                        //身份证号
                        inputXMLdoc.Check("request/body/patient/idNumber", false, out var idNumber02120);
                        //性别
                        inputXMLdoc.Check("request/body/patient/sex", false, out var sex02120, FieldType.String, SEX_TYPE);
                        //出生日期
                        inputXMLdoc.Check("request/body/patient/birthday", false, out var birthday02120, FieldType.Date);
                        //地址
                        inputXMLdoc.Check("request/body/patient/address", true, out var address02120);
                        //联系电话
                        inputXMLdoc.Check("request/body/patient/mobile", false, out var mobile02120);
                        //卡类型
                        inputXMLdoc.Check("request/body/card/cardType", false, out var cardType02120, FieldType.String, cardType);
                        //民族
                        inputXMLdoc.Check("request/body/card/nation", false, out var nation02120);
                        //卡号
                        inputXMLdoc.Check("request/body/card/cardNumber", true, out var cardNumber02120);
                        //密码（不用）
                        inputXMLdoc.Check("request/body/card/password", true, out var password02120);
                        //支付方式(不用)
                        inputXMLdoc.Check("request/body/payment/payType", true, out var payType02120, FieldType.String, payTypeDic);
                        //支付流水号
                        inputXMLdoc.Check("request/body/payment/payNumber", true, out var payNumber02120);
                        //支付金额(不用)
                        inputXMLdoc.Check("request/body/payment/payAmount", true, out var payAmount02120);
                        //门诊账户余额（不用）
                        inputXMLdoc.Check("request/body/payment/balance", true, out var balance02120);
                        //一体机id
                        inputXMLdoc.Check("request/body/terminal/terminalId", true, out var terminalId02120);
                        var patient02120 = new Patient();
                        patient02120.PatientName = (string)name02120;
                        patient02120.IdCardNo = (string)idNumber02120;
                        //性别转换
                        //if (sex02120.Equals("0"))
                        //    patient02120.Sex = Sex.Female;
                        //else if (sex02120.Equals("1"))
                        //    patient02120.Sex = Sex.Male;
                        //else
                        //    patient02120.Sex = Sex.UnKonw;
                        //patient02120.Birthday = (DateTime)birthday02120;
                        //patient02120.Address = (string)address02120;
                        //patient02120.Tel = (string)mobile02120;
                        //卡类型转换
                        //if (cardType02120.Equals("1"))
                        //    patient02120.CardType = CardType.OtherCard;
                        //else if (cardType02120.Equals("2"))
                        //    patient02120.CardType = CardType.OtherCard;
                        //else if (cardType02120.Equals("3"))
                        //    patient02120.CardType = CardType.HealthCard;
                        //else if (cardType02120.Equals("4"))
                        //    patient02120.CardType = CardType.IdCard;
                        //else if (cardType02120.Equals("5"))
                        //    patient02120.CardType = CardType.OtherCard;
                        patient02120.CarNo = (string)cardNumber02120;
                        patient02120.TransNo = (string)payNumber02120;
                        patient02120.Nation = (string)nation02120;
                        //if (!queryService.BindingCard(callNo_DongRuan, callName_DongRuan, patient02120, ref patient02120, ref errorMessage))
                        //    throw new InvalidOperationException(errorMessage);
                        body = new HIS_ATM_02120Body();
                        ((HIS_ATM_02120Body)body).PatientId = patient02120.PatientId;
                        ((HIS_ATM_02120Body)body).Sex = (string)sex02120;
                        ((HIS_ATM_02120Body)body).CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        ((HIS_ATM_02120Body)body).Note = "德宏州第二人民医院制";
                        break;
                    #endregion
                    #region 登录（目前先固定用身份证进行病人信息绑定）
                    case "HIS_ATM_02200":
                        //卡类型(固定身份证)
                        inputXMLdoc.Check("request/body/card/cardType", false, out var cardType02200, FieldType.Integer, cardType);
                        //卡号(身份证号)
                        inputXMLdoc.Check("request/body/card/cardNumber", false, out var cardNumber02200);
                        //终端信息
                        inputXMLdoc.Check("request/body/terminal/terminalId", true, out var terminalId02200);
                        //扩展信息（暂先判断姓名，性别，身份证号）
                        inputXMLdoc.Check("request/body/extend/name", true, out var name02200);
                        //身份证号
                        inputXMLdoc.Check("request/body/extend/idNumber", true, out var idNumber02200);
                        //性别
                        inputXMLdoc.Check("request/body/extend/sex", true, out var sex02200, FieldType.String, SEX_TYPE);
                        //出生日期
                        inputXMLdoc.Check("request/body/extend/birthday", true, out var birthday02200, FieldType.Date);
                        //地址
                        inputXMLdoc.Check("request/body/extend/address", true, out var address02200);
                        var patient02200 = new Patient();
                        //卡类型转换(目前仅支持4:身份证,6:PatientId)
                        if (cardType02200.Equals(4))
                        {
                            patient02200.CardType = Convert.ToInt32(cardType02200);
                            patient02200.CarNo = (string)cardNumber02200;
                            patient02200.PatientName = (string)name02200;
                            patient02200.IdCardNo = (string)idNumber02200;
                            patient02200.Sex = sex02200.ToString();
                            patient02200.Birthday = Convert.ToDateTime(IDCardHelper.GetBrithdayFromIdCard(idNumber02200.ToString()));
                            patient02200.Address = (string)address02200;
                            if (!accountService.LoginWithPersonId(callNo_DongRuan, callName_DongRuan, ref patient02200,
                            ref errorMessage))
                                throw new InvalidOperationException(errorMessage);
                        }
                        else if (cardType02200.Equals(6))
                        {
                            var patient = accountService.LoginWithPatientId(callNo_DongRuan, callName_DongRuan, cardNumber02200.ToString());
                            patient02200 = patient ?? throw new InvalidOperationException("未查询到相应的信息");
                        }
                        else
                        {
                            throw new InvalidOperationException("不支持的号码类型");
                        }
                        body = new HIS_ATM_02200Body();
                        ((HIS_ATM_02200Body)body).PatientId = patient02200.PatientId;
                        ((HIS_ATM_02200Body)body).Name = patient02200.PatientName;
                        ((HIS_ATM_02200Body)body).IdNumber = patient02200.IdCardNo;
                        ((HIS_ATM_02200Body)body).Sex = patient02200.Sex;
                        ((HIS_ATM_02200Body)body).Birthday = patient02200.Birthday.ToString("yyyy-MM-dd");
                        ((HIS_ATM_02200Body)body).Mobile = Convert.ToString(patient02200.Tel);
                        ((HIS_ATM_02200Body)body).Balance = "0";
                        ((HIS_ATM_02200Body)body).AccBalancezy = "0";
                        ((HIS_ATM_02200Body)body).CreateDate = patient02200.CreateDate.ToString("yyyy-MM-dd HH:mm:ss");
                        break;
                    #endregion
                    #region 当日挂号-预挂号
                    case "HIS_ATM_03130":
                        //科室ID
                        inputXMLdoc.Check("request/body/register/deptId", false, out var deptId03130);
                        //医生ID
                        inputXMLdoc.Check("request/body/register/doctorId", false, out var doctorId03130);
                        //患者编号
                        inputXMLdoc.Check("request/body/register/patientId", false, out var patientId03130);
                        int registerId03130 = 0;
                        string deptName03130 = string.Empty;
                        string address03130 = string.Empty;
                        string doctorName03130 = string.Empty;
                        string currentNumber03130 = string.Empty;
                        string queueNumber03130 = string.Empty;
                        decimal originAmount03130 = 0;
                        decimal totalAmount03130 = 0;

                        if (!registService.PrepareRegister(callNo_DongRuan, callName_DongRuan,
                            (string)deptId03130, (string)doctorId03130, (string)patientId03130,
                            ref registerId03130,
                            ref deptName03130,
                            ref address03130,
                            ref doctorName03130,
                            ref currentNumber03130,
                            ref queueNumber03130,
                            ref originAmount03130,
                            ref totalAmount03130,
                            ref errorMessage))
                            throw new InvalidOperationException(errorMessage);

                        body = new HIS_ATM_03130Body();
                        ((HIS_ATM_03130Body)body).RegisterId = Convert.ToString(registerId03130);
                        ((HIS_ATM_03130Body)body).DeptName = deptName03130.Trim();
                        ((HIS_ATM_03130Body)body).Address = address03130;
                        ((HIS_ATM_03130Body)body).DoctorName = doctorName03130.Trim();
                        ((HIS_ATM_03130Body)body).CurrentNumber = currentNumber03130.Trim();
                        ((HIS_ATM_03130Body)body).QueueNumber = queueNumber03130;
                        ((HIS_ATM_03130Body)body).OriginAmount = (originAmount03130 * 100).ToString("#0");
                        ((HIS_ATM_03130Body)body).TotalAmount = (totalAmount03130 * 100).ToString("#0");

                        break;
                    #endregion
                    #region 当日挂号-取消预挂号
                    case "HIS_ATM_03140":
                        //挂号信息
                        inputXMLdoc.Check("request/body/register/registerId", false, out var registerId03140, FieldType.Integer);
                        //终端信息
                        inputXMLdoc.Check("request/body/terminal/terminalId", true, out var terminalId03140);
                        //在响应头中返回成功或失败信息 1.失败，0.成功
                        if (!registService.RefundRegist(callNo_DongRuan, callName_DongRuan, registerId03140.ToString(), ref errorMessage))
                            throw new InvalidOperationException(errorMessage);
                        break;
                    #endregion
                    #region 当日挂号-挂号确认
                    case "HIS_ATM_03150":
                        //挂号编号                                
                        inputXMLdoc.Check("request/body/register/registerId", false, out var registerId03150, FieldType.Integer);
                        //患者编号                                
                        inputXMLdoc.Check("request/body/register/patientId", false, out var patientId03150);
                        //平台支付流水号
                        inputXMLdoc.Check("request/body/payment/orderNumber", false, out var orderNumber03150);
                        //支付类型
                        inputXMLdoc.Check("request/body/payment/payType", false, out var payType03150, FieldType.String, payTypeDic);
                        //支付流水号
                        inputXMLdoc.Check("request/body/payment/payNumber", false, out var payNumber03150);
                        //是否包含医保支付
                        inputXMLdoc.Check("request/body/payment/isMedicarePay", false, out var isMedicarePay03150);
                        bool flag03150 = true;
                        if (isMedicarePay03150.Equals("true"))
                        {
                            flag03150 = false;
                        }
                        //医保结算流水号
                        inputXMLdoc.Check("request/body/payment/medicareNumber", true, out var medicareNumber03150);
                        //自费金额
                        inputXMLdoc.Check("request/body/payment/payAmount", false, out var payAmount03150, FieldType.Money);
                        //东软是按分为单位传进来的，这里转换为元
                        decimal payAmount03150Trans = Convert.ToDecimal(payAmount03150) / 100;
                        //医保结算金额
                        inputXMLdoc.Check("request/body/payment/medicareAmount", flag03150, out var medicareAmount03150, FieldType.Money);
                        decimal medicareAmount03150Trans = Convert.ToDecimal(medicareAmount03150) / 100;
                        //支付总金额
                        inputXMLdoc.Check("request/body/payment/totalAmount", false, out var totalAmount03150, FieldType.Money);
                        decimal totalAmount03150Trans = Convert.ToDecimal(totalAmount03150) / 100;
                        //扩展信息
                        inputXMLdoc.Check("request/body/extend", true, out var extend03150);
                        //终端信息
                        inputXMLdoc.Check("request/body/terminal/terminalId", true, out var terminalId03150);

                        decimal payMoney03150;

                        if (isMedicarePay03150.Equals("true"))
                        {
                            if (!medicareAmount03150Trans.Equals(totalAmount03150Trans))
                                throw new InvalidOperationException("结算金额与应付金额不相等");
                            payMoney03150 = medicareAmount03150Trans;
                        }
                        else
                        {
                            if (!payAmount03150Trans.Equals(totalAmount03150Trans))
                                throw new InvalidOperationException("实付金额与应付金额不相等");
                            payMoney03150 = payAmount03150Trans;
                        }


                        string sourceNumber03150 = string.Empty;
                        string transFlow03150 = string.Empty;
                        DateTime? transactionTime03150 = null;
                        string currentNumber03150 = string.Empty;
                        string queueNumber03150 = string.Empty;
                        string clinicRange03150 = string.Empty;
                        string name03150 = string.Empty;
                        Sex sex03150 = Sex.UnKonw;
                        string deptName03150 = string.Empty;
                        string address03150 = string.Empty;
                        string doctorName03150 = string.Empty;
                        string duty03150 = string.Empty;
                        Dictionary<string, decimal> orders03150 = new Dictionary<string, decimal>();
                        PayType selfPayType03150 = PayType.现金;
                        if (payType03150.Equals("1"))
                        {
                            selfPayType03150 = PayType.现金;
                        }
                        else if (payType03150.Equals("2"))
                        {
                            selfPayType03150 = PayType.银联下卡;
                        }
                        else if (payType03150.Equals("3"))
                        {
                            selfPayType03150 = PayType.微信;
                        }
                        else if (payType03150.Equals("4"))
                        {
                            selfPayType03150 = PayType.支付宝;
                        }
                        else if (payType03150.Equals("5"))
                        {
                            selfPayType03150 = PayType.翼支付;
                        }
                        else if (payType03150.Equals("6"))
                        {
                            selfPayType03150 = PayType.就诊卡下卡;
                        }

                        if (!registService.RegistToday(callNo_DongRuan, callName_DongRuan, (int)registerId03150
                              , (string)patientId03150, (string)orderNumber03150, selfPayType03150
                              , (string)payNumber03150, (string)isMedicarePay03150, (string)medicareNumber03150
                              , payAmount03150Trans, medicareAmount03150Trans, payMoney03150
                              , (string)extend03150, (string)terminalId03150
                              , ref errorMessage, ref sourceNumber03150, ref transFlow03150
                              , ref transactionTime03150, ref currentNumber03150, ref queueNumber03150
                              , ref clinicRange03150, ref name03150
                              , ref sex03150, ref deptName03150, ref address03150
                              , ref doctorName03150, ref duty03150, ref orders03150
                              ))
                            throw new InvalidOperationException(errorMessage);

                        //TODO查询返回实体
                        body = new HIS_ATM_03150Body();
                        ((HIS_ATM_03150Body)body).SourceNumber = sourceNumber03150;
                        ((HIS_ATM_03150Body)body).TransFlow = transFlow03150;
                        ((HIS_ATM_03150Body)body).TransactionTime = transactionTime03150?.ToString("yyyy-MM-dd HH:mm:ss");
                        ((HIS_ATM_03150Body)body).CurrentNumber = currentNumber03150;
                        ((HIS_ATM_03150Body)body).QueueNumber = queueNumber03150;
                        ((HIS_ATM_03150Body)body).ClinicRange = clinicRange03150;
                        ((HIS_ATM_03150Body)body).PatientId = (string)patientId03150;
                        ((HIS_ATM_03150Body)body).Name = name03150;
                        if (sex03150 == Sex.Male)
                            ((HIS_ATM_03150Body)body).Sex = "0";
                        else if (sex03150 == Sex.Female)
                            ((HIS_ATM_03150Body)body).Sex = "1";
                        else
                            ((HIS_ATM_03150Body)body).Sex = "3";
                        ((HIS_ATM_03150Body)body).DeptName = deptName03150;
                        ((HIS_ATM_03150Body)body).Address = address03150;
                        ((HIS_ATM_03150Body)body).DoctorName = doctorName03150;
                        ((HIS_ATM_03150Body)body).Duty = duty03150;

                        List<HIS_ATM_03150Attr> list03150 = new List<HIS_ATM_03150Attr>();
                        orders03150.ToList().ForEach(c => list03150.Add(new HIS_ATM_03150Attr { Name = c.Key, Price = (c.Value * 100).ToString("#0") }));
                        ((HIS_ATM_03150Body)body).Orders = list03150;
                        break;
                    #endregion
                    #region 预约挂号-预挂号（占号）
                    case "HIS_ATM_04130":
                        //预约日期
                        inputXMLdoc.Check("request/body/register/appointDate", false, out var appointDate04130, FieldType.Date);
                        //预约时间段ID
                        inputXMLdoc.Check("request/body/register/clinicRangeId", false, out var clinicRangeId04130);
                        //科室ID
                        inputXMLdoc.Check("request/body/register/deptId", false, out var deptId04130);
                        //医生ID
                        inputXMLdoc.Check("request/body/register/doctorId", false, out var doctorId04130);
                        //患者编号
                        inputXMLdoc.Check("request/body/register/patientId", false, out var patientId04130);

                        var result = registService.PrepareReservationRegist(callNo_DongRuan, callName_DongRuan, Convert.ToDateTime(appointDate04130), (string)clinicRangeId04130, (string)deptId04130, (string)doctorId04130, (string)patientId04130);



                        if (result.Count == 0)
                        {
                            throw new InvalidOperationException("预约失败,没有相关的信息");
                        }


                        body = new HIS_ATM_04130Body();
                        ((HIS_ATM_04130Body)body).RegisterId = Convert.ToString(result["registerId"]);
                        ((HIS_ATM_04130Body)body).DeptName = (string)result["deptName"];
                        ((HIS_ATM_04130Body)body).Address = (string)result["address"];
                        ((HIS_ATM_04130Body)body).DoctorName = (string)result["doctorName"];
                        ((HIS_ATM_04130Body)body).CurrentNumber = (string)result["currentNumber"];
                        ((HIS_ATM_04130Body)body).QueueNumber = (string)result["queueNumber"];
                        ((HIS_ATM_04130Body)body).ClinicRange = (string)result["clinicRange"];
                        ((HIS_ATM_04130Body)body).OriginAmount = ((decimal)result["originAmount"] * 100).ToString("#0");
                        ((HIS_ATM_04130Body)body).TotalAmount = ((decimal)result["totalAmount"] * 100).ToString("#0");

                        break;
                    #endregion
                    #region 预约挂号-取消预挂号
                    case "HIS_ATM_04140":
                        //挂号编号
                        inputXMLdoc.Check("request/body/register/registerId", false, out var registerId04140);
                        //终端信息
                        inputXMLdoc.Check("request/body/terminal/terminalId", true, out var terminalId04140);
                        //在响应头中返回成功或失败信息 1.失败，0.成功
                        if (!registService.RefundReservationRegist(callNo_DongRuan, callName_DongRuan, (string)registerId04140, ref errorMessage))
                        {
                            throw new InvalidOperationException(errorMessage);
                        }

                        break;
                    #endregion
                    #region 预约挂号-挂号确认
                    case "HIS_ATM_04150":
                        //挂号编号
                        inputXMLdoc.Check("request/body/register/registerId", false, out var registerId04150);
                        //患者编号
                        inputXMLdoc.Check("request/body/register/patientId", false, out var patientId04150);
                        //平台流水号
                        inputXMLdoc.Check("request/body/payment/orderNumber", false, out var orderNumber04150);
                        //支付类型
                        inputXMLdoc.Check("request/body/payment/payType", false, out var payType04150, FieldType.String, payTypeDic);
                        //支付流水号
                        inputXMLdoc.Check("request/body/payment/payNumber", true, out var payNumber04150);
                        //是否包含医保支付
                        inputXMLdoc.Check("request/body/payment/isMedicarePay", false, out var isMedicarePay04150);
                        bool flag04150 = true;
                        if (isMedicarePay04150.Equals("true"))
                        {
                            flag04150 = false;
                        }

                        //医保结算流水号
                        inputXMLdoc.Check("request/body/payment/medicareNumber", true, out var medicareNumber04150);
                        //自费金额
                        inputXMLdoc.Check("request/body/payment/payAmount", false, out var payAmount04150);
                        //东软是按分为单位传进来的，这里转换为元
                        decimal payAmount04150Trans = Convert.ToDecimal(payAmount04150) / 100;
                        //医保结算金额
                        inputXMLdoc.Check("request/body/payment/medicareAmount", flag04150, out var medicareAmount04150);
                        decimal medicareAmount04150Trans = Convert.ToDecimal(medicareAmount04150) / 100;
                        //支付总金额
                        inputXMLdoc.Check("request/body/payment/totalAmount", false, out var totalAmount04150);
                        decimal totalAmount04150Trans = Convert.ToDecimal(totalAmount04150) / 100;
                        //医保信息、商保信息
                        inputXMLdoc.Check("request/body/extend", true, out var extend04150);
                        //终端信息
                        inputXMLdoc.Check("request/body/terminal/terminalId", false, out var terminalId04150);
                        decimal payMoney04150;
                        if (isMedicarePay04150.Equals("true"))
                        {
                            if (!medicareAmount04150Trans.Equals(totalAmount04150Trans))
                                throw new InvalidOperationException("结算金额与应付金额不相等");
                            payMoney04150 = medicareAmount04150Trans;
                        }
                        else
                        {
                            if (!payAmount04150Trans.Equals(totalAmount04150Trans))
                                throw new InvalidOperationException("支付金额与应付金额不相等");
                            payMoney04150 = payAmount04150Trans;
                        }

                        DateTime? appointDate04150 = null;
                        string sourceNumber04150 = string.Empty;
                        string transFlow04150 = string.Empty;
                        string transactionTime04150 = null;
                        string currentNumber04150 = string.Empty;
                        string queueNumber04150 = string.Empty;
                        string clinicRange04150 = string.Empty;
                        string name04150 = string.Empty;
                        Sex sex04150 = Sex.UnKonw;
                        string deptName04150 = string.Empty;
                        string address04150 = string.Empty;
                        string doctorName04150 = string.Empty;
                        string duty04150 = string.Empty;
                        Dictionary<string, decimal> orders04150 = new Dictionary<string, decimal>();
                        PayType selfPayType04150 = PayType.现金;
                        if (payType04150.Equals("1"))
                        {
                            selfPayType04150 = PayType.现金;
                        }
                        else if (payType04150.Equals("2"))
                        {
                            selfPayType04150 = PayType.银联下卡;
                        }
                        else if (payType04150.Equals("3"))
                        {
                            selfPayType04150 = PayType.微信;
                        }
                        else if (payType04150.Equals("4"))
                        {
                            selfPayType04150 = PayType.支付宝;
                        }
                        else if (payType04150.Equals("5"))
                        {
                            selfPayType04150 = PayType.翼支付;
                        }
                        else if (payType04150.Equals("6"))
                        {
                            selfPayType04150 = PayType.就诊卡下卡;
                        }

                        if (!registService.ReservationRegist(callNo_DongRuan, callName_DongRuan, Convert.ToInt32(registerId04150)
                              , (string)patientId04150, (string)orderNumber04150, selfPayType04150
                              , (string)payNumber04150, (string)isMedicarePay04150, (string)medicareNumber04150
                              , payMoney04150, medicareAmount04150Trans, totalAmount04150Trans
                              , (string)extend04150, (string)terminalId04150
                              , ref errorMessage, ref appointDate04150, ref sourceNumber04150, ref transFlow04150
                              , ref transactionTime04150, ref currentNumber04150, ref queueNumber04150
                              , ref clinicRange04150, ref name04150
                              , ref sex04150, ref deptName04150, ref address04150
                              , ref doctorName04150, ref duty04150, ref orders04150
                              ))
                            throw new InvalidOperationException(errorMessage);


                        //TODO数据查询
                        body = new HIS_ATM_04150Body();
                        ((HIS_ATM_04150Body)body).AppointDate = appointDate04150?.ToString("yyyy-MM-dd HH:mm:ss");
                        ((HIS_ATM_04150Body)body).SourceNumber = sourceNumber04150;
                        ((HIS_ATM_04150Body)body).TransFlow = transFlow04150;
                        ((HIS_ATM_04150Body)body).TransactionTime = transactionTime04150.ToString();
                        ((HIS_ATM_04150Body)body).CurrentNumber = currentNumber04150;
                        ((HIS_ATM_04150Body)body).QueueNumber = queueNumber04150;
                        ((HIS_ATM_04150Body)body).ClinicRange = clinicRange04150;
                        ((HIS_ATM_04150Body)body).PatientId = (string)patientId04150;
                        ((HIS_ATM_04150Body)body).Name = name04150;
                        if (sex04150 == Sex.Male)
                            ((HIS_ATM_04150Body)body).Sex = "0";
                        else if (sex04150 == Sex.Female)
                            ((HIS_ATM_04150Body)body).Sex = "1";
                        else
                            ((HIS_ATM_04150Body)body).Sex = "3";
                        ((HIS_ATM_04150Body)body).DeptName = deptName04150;
                        ((HIS_ATM_04150Body)body).Address = address04150;
                        ((HIS_ATM_04150Body)body).DoctorName = doctorName04150;
                        ((HIS_ATM_04150Body)body).Duty = duty04150;

                        List<HIS_ATM_04150Attr> list04150 = new List<HIS_ATM_04150Attr>();
                        orders04150.ToList().ForEach(c => list04150.Add(new HIS_ATM_04150Attr { Name = c.Key, Price = (c.Value * 100).ToString("#0") }));
                        ((HIS_ATM_04150Body)body).Orders = list04150;

                        break;
                    #endregion
                    #region 预约取号-取号
                    case "HIS_ATM_04220":
                        //挂号编号
                        inputXMLdoc.Check("request/body/patient/registerId", false, out var registerId04220);
                        //终端信息
                        inputXMLdoc.Check("request/body/terminal/terminalId", false, out var terminalId04220);
                        //TODO调用后台
                        Dictionary<string, object> result04220 = registService.GetReservationInfo(callNo_DongRuan, callName_DongRuan, (string)registerId04220);

                        body = new HIS_ATM_04220Body();
                        ((HIS_ATM_04220Body)body).AppointDate = (string)result04220["AppointDate"];
                        ((HIS_ATM_04220Body)body).SourceNumber = (string)result04220["SourceNumber"];
                        ((HIS_ATM_04220Body)body).TransFlow = (string)result04220["TransFlow"];
                        ((HIS_ATM_04220Body)body).TransactionTime = (string)result04220["TransactionTime"];
                        ((HIS_ATM_04220Body)body).CurrentNumber = (string)result04220["CurrentNumber"];
                        ((HIS_ATM_04220Body)body).QueueNumber = (string)result04220["QueueNumber"];
                        ((HIS_ATM_04220Body)body).ClinicRange = (string)result04220["ClinicRange"];
                        ((HIS_ATM_04220Body)body).PatientId = (string)result04220["PatientId"];
                        ((HIS_ATM_04220Body)body).Name = (string)result04220["Name"];
                        ((HIS_ATM_04220Body)body).Sex = (string)result04220["Sex"];
                        ((HIS_ATM_04220Body)body).DeptName = (string)result04220["DeptName"];
                        ((HIS_ATM_04220Body)body).Address = (string)result04220["Address"];
                        ((HIS_ATM_04220Body)body).DoctorName = (string)result04220["DoctorName"];
                        ((HIS_ATM_04220Body)body).Duty = (string)result04220["Duty"];

                        List<HIS_ATM_04220Attr> list04220 = new List<HIS_ATM_04220Attr>();
                        foreach (KeyValuePair<string, object> kvp in (Dictionary<string, object>)result04220["oders"])
                        {
                            HIS_ATM_04220Attr attr04220 = new HIS_ATM_04220Attr();
                            attr04220.Name = (string)kvp.Key;
                            attr04220.Price = (string)kvp.Value;

                            list04220.Add(attr04220);
                        }
                        ((HIS_ATM_04220Body)body).Orders = list04220;
                        break;
                    #endregion
                    #region 门诊缴费确认(院方表示就按门诊流水号来缴费)
                    case "HIS_ATM_05140":
                        //患者编号
                        inputXMLdoc.Check("request/body/patient/patientId", false, out var patientId05140);
                        //缴费编号
                        inputXMLdoc.Check("request/body/patient/feeNumber", false, out var feeNumber05140);
                        //费用编号类型(院方确定按门诊流水号来缴费故号别固定为门诊号)
                        inputXMLdoc.Check("request/body/patient/feeNumberType", true, out var feeNumberType05140, FieldType.Integer, feeNumberTypeDic);
                        //平台流水号
                        inputXMLdoc.Check("request/body/payment/orderNumber", false, out var orderNumber05140);
                        //支付类型
                        inputXMLdoc.Check("request/body/payment/payType", false, out var payType05140, FieldType.String, payTypeDic);
                        //支付流水号
                        inputXMLdoc.Check("request/body/payment/payNumber", true, out var payNumber05140);
                        //是否包含医保支付
                        inputXMLdoc.Check("request/body/payment/isMedicarePay", false, out var isMedicarePay05140, FieldType.String, isMedicarePayDic);
                        bool flag05140 = true;
                        if (isMedicarePay05140.Equals("true"))
                        {
                            flag05140 = false;
                        }
                        //医保结算流水号
                        inputXMLdoc.Check("request/body/payment/medicareNumber", true, out var medicareNumber05140);
                        //自费金额
                        inputXMLdoc.Check("request/body/payment/payAmount", false, out var payAmount05140);
                        Decimal payAmount05140Trans = Convert.ToDecimal(payAmount05140) / 100;
                        //医保结算金额
                        inputXMLdoc.Check("request/body/payment/medicareAmount", flag05140, out var medicareAmount05140);
                        Decimal medicareAmount05140Trans = Convert.ToDecimal(medicareAmount05140) / 100;
                        //支付总金额
                        inputXMLdoc.Check("request/body/payment/totalAmount", false, out var totalAmount05140);
                        Decimal totalAmount05140Trans = Convert.ToDecimal(totalAmount05140) / 100;
                        //原始金额
                        inputXMLdoc.Check("request/body/payment/originAmount", true, out var originAmount05140);
                        //Decimal originAmount05140Trans = Convert.ToDecimal(originAmount05140) / 100;
                        //扩展信息
                        inputXMLdoc.Check("request/body/extend", true, out var extend05140);
                        //终端信息
                        inputXMLdoc.Check("request/body/terminal/terminalId", false, out var terminalId05140);
                        decimal payMoney;
                        //判断患者所缴费用与总金额是否相等
                        if (isMedicarePay05140.Equals("true"))
                        {
                            if (!medicareAmount05140Trans.Equals(totalAmount05140Trans))
                                throw new InvalidOperationException("结算金额与应付金额不相等");
                            payMoney = medicareAmount05140Trans;
                        }
                        else
                        {
                            if (!payAmount05140Trans.Equals(totalAmount05140Trans))
                                throw new InvalidOperationException("支付金额与应付金额不相等");
                            payMoney = payAmount05140Trans;
                        }

                        if (!clinicService.PayRecipe(callNo_DongRuan, callName_DongRuan, Convert.ToString(patientId05140), Convert.ToInt32(feeNumber05140)
                                          , Convert.ToString(orderNumber05140), Convert.ToInt16(payType05140), Convert.ToString(orderNumber05140)
                                          , Convert.ToString(isMedicarePay05140), Convert.ToString(medicareNumber05140)
                                          , payMoney, medicareAmount05140Trans, totalAmount05140Trans
                                          , Convert.ToString(extend05140), Convert.ToString(terminalId05140), ref errorMessage
                                          , out List<ClinicPayResult> recipeSubMZNumList05140))
                            throw new InvalidOperationException(errorMessage);
                        body = new HIS_ATM_05140Body();
                        List<HIS_ATM_05140Attr> list05140 = new List<HIS_ATM_05140Attr>();
                        ((HIS_ATM_05140Body)body).MedicalCode = recipeSubMZNumList05140.First().MZNum;
                        ((HIS_ATM_05140Body)body).TransFlow = Convert.ToString(recipeSubMZNumList05140.First().TransNo);
                        ((HIS_ATM_05140Body)body).TransactionTime = Convert.ToString(recipeSubMZNumList05140.FirstOrDefault().FPDate);
                        recipeSubMZNumList05140.ForEach(c => list05140.Add(new HIS_ATM_05140Attr
                        {
                            FeesItem = c.CFName,
                            ItemId = Convert.ToString(c.Id),
                            ExecuteDept = c.DoctDeptName,
                            ExecuteDeptAddr = string.Empty,
                            ItemName = c.ItemName,
                            Unit = c.Unit,
                            Count = c.Quantity.ToString("#0"),
                            Price = (c.Price * 100).ToString("#0"),
                            Amount = (c.Price * 100 * Convert.ToDecimal(c.Quantity)).ToString("#0"),
                        }));
                        ((HIS_ATM_05140Body)body).OrderItems = list05140;
                        break;
                    #endregion
                    #region 在线充值、银行卡充值、现金充值
                    case "HIS_ATM_07100":
                        break;
                    #endregion
                    #region 余额支付
                    case "HIS_ATM_08100":
                        break;
                    #endregion
                    #region 修改密码
                    case "HIS_ATM_10200":
                        break;
                    #endregion
                    #region 更新检验报告单打印状态
                    case "HIS_ATM_11300":
                        //患者ID
                        inputXMLdoc.Check("request/body/patientId", false, out var patientId11300);
                        //报告编号
                        inputXMLdoc.Check("request/body/reportNo", false, out var reportNo11300);
                        //报告种类名称
                        inputXMLdoc.Check("request/body/reportKind", false, out var reportKind11300);
                        //打印状态
                        inputXMLdoc.Check("request/body/printStatus", false, out var printStatus11300);
                        //终端信息
                        inputXMLdoc.Check("request/body/terminal/terminalId", false, out var terminalId11300);

                        //TODO数据交互
                        break;
                    #endregion
                    #region 更新检查报告单打印状态
                    case "HIS_ATM_11600":
                        //患者ID
                        inputXMLdoc.Check("request/body/patientId", false, out var patientId11600);
                        //报告编号
                        inputXMLdoc.Check("request/body/reportNo", false, out var reportNo11600);
                        //打印状态
                        inputXMLdoc.Check("request/body/printStatus", false, out var printStatus11600);
                        //终端信息
                        inputXMLdoc.Check("request/body/terminal/terminalId", false, out var terminalId11600);

                        throw new InvalidOperationException("暂不提供");
                    //UpDateResult result11600 = queryService.UpDateCheckRepot(callNo_DongRuan, callName_DongRuan
                    //                                                  , (string)patientId11600, Convert.ToInt16(reportNo11600)
                    //                                                  , Convert.ToInt16(printStatus11600));
                    //if (result11600.ResultCode.Equals(-1))
                    //    throw new InvalidOperationException(result11600.ResultText);
                    //break;
                    #endregion
                    #region 入院办理
                    case "HIS_ATM_14200":
                        break;
                    #endregion
                    #region 出院结算
                    case "HIS_ATM_14500":
                        break;
                    #endregion
                    #region 本次住院充值
                    case "HIS_ATM_14700":
                        break;
                        #endregion
                }
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }
            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                head.Code = "0";
                head.Error = errorMessage;
                body = null;
            }
            outputXML.Body = body;
            var resultXml = XmlHelper.Serializer(outputXML.GetType(), outputXML, arg1);
            log.Info(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "返回值: " + resultXml);
            return resultXml;
        }

        /// <summary>
        /// 查询服务接口
        /// </summary>
        /// <param name="arg0">clientNode 客户端标识</param>
        /// <param name="arg1">buzzNumb 交易业务编码</param>
        /// <param name="arg2">version 交易版本号</param>
        /// <param name="arg3">content 交易报文内容</param>
        /// <returns></returns>
        [WebMethod]
        [return: XmlElement("return")]
        public string query(string arg0, string arg1, string arg2, string arg3)
        {
            #region query方法公共处理
            log.Info(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "入参:arg0" + arg0 + " arg1:" + arg1 + " arg2:" + arg2 + " arg3:" + arg3);
            //入参
            XmlDocument inputXMLdoc = new XmlDocument();
            inputXMLdoc.LoadXml(arg3.Trim());
            //返回值映射
            XMLMapper outputXML = new XMLMapper();
            CommonHead head = new CommonHead();
            CommonBody body = new CommonBody();
            outputXML.Head = head;
            head.Fun = arg1;
            head.Version = "1.0";
            head.Code = "1";
            string errorMessage = string.Empty;
            #endregion

            try
            {
                switch (arg1)
                {
                    #region 检测医院HIS网络状态
                    case "HIS_ATM_01000":
                        inputXMLdoc.Check("request/body/currentTime", false, out var currentTime, FieldType.Date);
                        //测试
                        body = new HIS_ATM_01000Body();
                        ((HIS_ATM_01000Body)body).CurrentTime = DateTime.Now.ToString();
                        break;
                    #endregion
                    #region  办卡信息校验
                    case "HIS_ATM_02110":
                        //姓名
                        inputXMLdoc.Check("request/body/patient/name", false, out var name);
                        //身份证号
                        inputXMLdoc.Check("request/body/patient/idNumber", false, out var idNumber);
                        //性别
                        inputXMLdoc.Check("request/body/patient/sex", false, out var sex, FieldType.String, SEX_TYPE);
                        //出生日期
                        inputXMLdoc.Check("request/body/patient/birthday", false, out var birthday, FieldType.Date);
                        Patient patient = new Patient();
                        patient.PatientName = (string)name;
                        patient.IdCardNo = (string)idNumber;
                        //if (sex.Equals("0"))
                        //    patient.Sex = Sex.Female;
                        //else if (sex.Equals("1"))
                        //    patient.Sex = Sex.Male;
                        //else
                        //    patient.Sex = Sex.UnKonw;
                        //patient.TrimAllStrings();
                        //if (!queryService.CheckPatient(callNo_DongRuan, callName_DongRuan, patient, out var result))
                        //    throw new InvalidOperationException(result);
                        break;
                    #endregion
                    #region 当日挂号-当天有号科室
                    case "HIS_ATM_03110":
                        //科室编号
                        inputXMLdoc.Check("request/body/dept/deptId", false, out var deptId03110);
                        string deptId03110Str = (string)deptId03110;
                        body = new HIS_ATM_03110Body();
                        List<HIS_ATM_03110Attr> list03110 = new List<HIS_ATM_03110Attr>();
                        if (deptId03110Str.ToLower().Equals("all"))
                        {
                            registService.GetSecondDept4Live(callNo_DongRuan, callName_DongRuan, string.Empty, out var secondDepts);
                            ((List<SecondDept>)secondDepts).ForEach(c => list03110.Add(
                                new HIS_ATM_03110Attr()
                                {
                                    DeptId = c.KSCode,
                                    Name = c.KSName,
                                    Descript = c.Description,
                                    IsRegByDept = "0",
                                    HasChildDept = "0",
                                    RemainTicket = "0",
                                    TotalAmount = "0"
                                }));
                        }
                        else
                        {
                            registService.GetSecondDept4Live(callNo_DongRuan, callName_DongRuan, deptId03110Str, out var secondDepts);
                            ((List<SecondDept>)secondDepts).ForEach(c => list03110.Add(
                                new HIS_ATM_03110Attr()
                                {
                                    DeptId = c.KSCode,
                                    Name = c.KSName,
                                    Descript = c.Description,
                                    IsRegByDept = "0",
                                    HasChildDept = "0",
                                    RemainTicket = "0",
                                    TotalAmount = "0"
                                }));
                        }
                        ((HIS_ATM_03110Body)body).Dept = list03110;
                        break;
                    #endregion
                    #region 当日挂号-当天的医生
                    case "HIS_ATM_03120":
                        inputXMLdoc.Check("request/body/dept/deptId", false, out var deptId03120);
                        body = new HIS_ATM_03120Body();
                        List<HIS_ATM_03120Attr> list03120 = new List<HIS_ATM_03120Attr>();
                        registService.GetDoct4Live(callNo_DongRuan, callName_DongRuan, (string)deptId03120, string.Empty, false, out var docts);
                        ((List<Doct>)docts).ForEach(c => list03120.Add(
                            new HIS_ATM_03120Attr()
                            {
                                DoctorId = c.DoctCode,
                                Name = c.DoctName,
                                Descript = c.Descripton,
                                Specialty = c.Specialty,
                                Duty = Convert.IsDBNull(c.TitleName) ? string.Empty : c.TitleName,
                                TotalAmount = ((c.RegFee + c.ClinicFee) * 100).ToString("#0"),
                                RemainTicket = Convert.ToString(c.RemainSourceCount)
                            }));

                        ((HIS_ATM_03120Body)body).Doctors = list03120;
                        break;
                    #endregion
                    #region 预约挂号-查询预约排班日期 （直接在当前日期上加7天返回给他）
                    case "HIS_ATM_04100":
                        inputXMLdoc.Check("request/body/currentTime", false, out var currentTime04100);
                        body = new HIS_ATM_04100Body();
                        string stopBegDate = string.Empty;
                        string stopEndDate = string.Empty;

                        List<HIS_ATM_04100Attr> list04100 = new List<HIS_ATM_04100Attr>();

                        for (int i = 1; i <= 7; i++)
                        {
                            HIS_ATM_04100Attr attr04100 = new HIS_ATM_04100Attr();
                            attr04100.Date = DateTime.Now.AddDays(i).ToString("yyyy-MM-dd");
                            list04100.Add(attr04100);
                        }

                        ((HIS_ATM_04100Body)body).AppointDays = list04100;
                        break;
                    #endregion
                    #region 预约挂号-查询预约日期有号科室
                    case "HIS_ATM_04110":
                        //预约日期
                        inputXMLdoc.Check("request/body/dept/appointDate", false, out var appointDate04100, FieldType.DateTime);
                        //如果为All取一级科室
                        inputXMLdoc.Check("request/body/dept/deptId", true, out var deptId04100);
                        string deptId04110Str = (string)deptId04100;
                        body = new HIS_ATM_04110Body();
                        List<HIS_ATM_04110Attr> list04110 = new List<HIS_ATM_04110Attr>();
                        if (deptId04110Str.ToLower().Equals("all"))
                        {
                            registService.GetSecondDept4Reservation(callNo_DongRuan, callName_DongRuan, string.Empty, Convert.ToDateTime(appointDate04100), out var secondDepts);
                            ((List<SecondDept>)secondDepts).ForEach(c => list04110.Add(
                                new HIS_ATM_04110Attr()
                                {
                                    DeptId = c.KSCode,
                                    Name = c.KSName.Trim(),
                                    Descript = c.Description,
                                    IsRegByDept = "0",
                                    HasChildDept = "0",
                                    RemainTicket = "0",
                                    TotalAmount = "0"
                                }));

                        }
                        else
                        {
                            registService.GetSecondDept4Reservation(callNo_DongRuan, callName_DongRuan, deptId04110Str, Convert.ToDateTime(appointDate04100), out var secondDepts);
                            ((List<SecondDept>)secondDepts).ForEach(c => list04110.Add(
                                new HIS_ATM_04110Attr()
                                {
                                    DeptId = c.KSCode,
                                    Name = c.KSName.Trim(),
                                    Descript = c.Description,
                                    IsRegByDept = "0",
                                    HasChildDept = "0",
                                    RemainTicket = "0",
                                    TotalAmount = "0"
                                }));
                        }
                        ((HIS_ATM_04110Body)body).Depts = list04110;
                        break;
                    #endregion
                    #region 预约挂号-当天的医生
                    case "HIS_ATM_04120":
                        inputXMLdoc.Check("request/body/dept/appointDate", false, out var appointDate04120, FieldType.DateTime);
                        inputXMLdoc.Check("request/body/dept/deptId", false, out var deptId04120);

                        body = new HIS_ATM_04120Body();
                        List<HIS_ATM_04120Attr> list04120 = new List<HIS_ATM_04120Attr>();
                        registService.GetDoct4Reservation(callNo_DongRuan, callName_DongRuan, (string)deptId04120, string.Empty, Convert.ToDateTime(appointDate04120), false, out var docts04120);
                        ((List<Doct>)docts04120).ForEach(c => list04120.Add(
                            new HIS_ATM_04120Attr()
                            {
                                DoctorId = c.DoctCode,
                                Name = c.DoctName,
                                Descript = c.Descripton,
                                Specialty = c.Specialty,
                                Duty = c.TitleName,
                                TotalAmount = ((c.RegFee + c.ClinicFee) * 100).ToString("#0"),
                                RemainTicket = Convert.ToString(c.RemainSourceCount)
                            }));
                        ((HIS_ATM_04120Body)body).Doctors = list04120;
                        break;
                    #endregion
                    #region 预约挂号-预约医生时间段
                    case "HIS_ATM_04125":
                        inputXMLdoc.Check("request/body/doctor/appointDate", false, out var appointDate, FieldType.Date);
                        inputXMLdoc.Check("request/body/doctor/deptId", false, out var deptId04125);
                        inputXMLdoc.Check("request/body/doctor/doctorId", false, out var doctorId04125);

                        var result04125 = registService.GetReservationTidByDoctor(callNo_DongRuan, callName_DongRuan, Convert.ToDateTime(appointDate), (string)deptId04125, (string)doctorId04125);
                        List<HIS_ATM_04125Attr> list04125 = new List<HIS_ATM_04125Attr>();
                        if (result04125.Count == 0)
                        {
                            throw new InvalidOperationException("未查询到相应的信息");
                        }
                        body = new HIS_ATM_04125Body();
                        foreach (TimeInterval time in result04125)
                        {
                            HIS_ATM_04125Attr attr04125 = new HIS_ATM_04125Attr();
                            attr04125.ClinicRangeId = time.TimeIntervalId;
                            attr04125.ClinicRange = time.TimeIntervalRange;
                            list04125.Add(attr04125);
                        }
                        ((HIS_ATM_04125Body)body).Intervals = list04125;
                        break;
                    #endregion
                    #region 预约挂号-预约科室时间段
                    case "HIS_ATM_04126":
                        //预约日期
                        inputXMLdoc.Check("request/body/dept/appointDate", false, out var appointDate04126, FieldType.Date);
                        //科室Id
                        inputXMLdoc.Check("request/body/dept/deptId", false, out var deptId04126);

                        var result04126 = registService.GetReservationTidByDepartment(callNo_DongRuan, callName_DongRuan, Convert.ToDateTime(appointDate04126), (string)deptId04126);
                        List<HIS_ATM_04126Attr> list04126 = new List<HIS_ATM_04126Attr>();
                        body = new HIS_ATM_04126Body();

                        foreach (TimeInterval time in result04126)
                        {
                            HIS_ATM_04126Attr attr04126 = new HIS_ATM_04126Attr();
                            attr04126.ClinicRangeId = time.TimeIntervalId;
                            attr04126.ClinicRange = time.TimeIntervalRange;
                            list04126.Add(attr04126);
                        }
                        ((HIS_ATM_04126Body)body).Intervals = list04126;
                        break;
                    #endregion
                    #region 预约取号-列表
                    case "HIS_ATM_04210":
                        //患者Id
                        inputXMLdoc.Check("request/body/patient/patientId", false, out var patientId04210);

                        List<Dictionary<string, string>> listDic = registService.GetReservationList(callNo_DongRuan, callName_DongRuan, (string)patientId04210);
                        List<HIS_ATM_04210Attr> list04210 = new List<HIS_ATM_04210Attr>();
                        foreach (Dictionary<string, string> dic in listDic)
                        {
                            HIS_ATM_04210Attr attr04210 = new HIS_ATM_04210Attr();
                            attr04210.RegisterId = dic["registerId"];
                            attr04210.DeptName = dic["deptName"];
                            attr04210.RegTime = dic["regTime"];
                            attr04210.Price = dic["price"];
                            attr04210.RegisterStatus = dic["registerStatus"];
                            list04210.Add(attr04210);
                        }

                        body = new HIS_ATM_04210Body();
                        ((HIS_ATM_04210Body)body).Appointments = list04210;

                        break;
                    #endregion
                    #region 门诊未缴费记录(queryType = 1:未缴费,queryType = 2:已缴费)
                    case "HIS_ATM_05110":
                        //患者编号
                        inputXMLdoc.Check("request/body/patient/patientId", false, out var patientId05110);
                        //查询类别
                        inputXMLdoc.Check("request/body/patient/queryType", false, out var queryType05110, FieldType.Integer, queryTypeDic);

                        if (!clinicService.GetPaymentSheetList(callNo_DongRuan, callName_DongRuan, (string)patientId05110, out IList<RegistSheet> registSheetList, (int)queryType05110))
                            throw new InvalidOperationException("未查询到缴费记录");

                        body = new HIS_ATM_05110Body();
                        List<HIS_ATM_05110Attr> list05110 = new List<HIS_ATM_05110Attr>();
                        foreach (RegistSheet regist in registSheetList)
                        {
                            HIS_ATM_05110Attr attr05110 = new HIS_ATM_05110Attr();
                            attr05110.RegisterId = Convert.ToString(regist.MZNum).Trim();
                            attr05110.ClinicNo = Convert.ToString(regist.MZNum).Trim();
                            attr05110.RegDeptName = regist.DeptName.Trim();
                            attr05110.DoctorName = regist.DoctName.Trim();
                            attr05110.VisitTime = regist.ProcessDate.ToString();
                            list05110.Add(attr05110);
                        }
                        ((HIS_ATM_05110Body)body).OutPatients = list05110;
                        break;
                    #endregion
                    #region 查询未缴费处方清单
                    case "HIS_ATM_05120":
                        //门诊流水号
                        inputXMLdoc.Check("request/body/patient/clinicNo", false, out var clinicNo05120);

                        if (!clinicService.GetUnPayRecipeList(callNo_DongRuan, callName_DongRuan, (string)clinicNo05120, string.Empty, out IList<Recipe> recipeList05120))
                            throw new InvalidOperationException("未查询到相应的记录");

                        body = new HIS_ATM_05120Body();
                        List<HIS_ATM_05120Attr> list05120 = new List<HIS_ATM_05120Attr>();
                        HIS_ATM_05120Amount amount05120 = new HIS_ATM_05120Amount();
                        amount05120.ClinicNo = (string)clinicNo05120;
                        decimal totalMoneyTemp05120 = 0;

                        var groupRecipeList = recipeList05120.GroupBy(m => new
                        {
                            m.RecipeId,
                            m.CFName,
                            m.ExeDeptName,
                            m.RecipeAmount
                        })
                                                              .Select(a => new
                                                              {
                                                                  a.Key.RecipeId,
                                                                  a.Key.CFName,
                                                                  a.Key.ExeDeptName,
                                                                  a.Key.RecipeAmount
                                                              }).ToList();

                        foreach (var recipe in groupRecipeList)
                        {
                            //金额换算成分
                            totalMoneyTemp05120 = totalMoneyTemp05120 + (recipe.RecipeAmount * 100);
                            HIS_ATM_05120Attr attr05120 = new HIS_ATM_05120Attr();
                            attr05120.OrderNo = Convert.ToString(recipe.RecipeId);
                            attr05120.FeesItem = recipe.CFName.Trim();
                            attr05120.DeptName = recipe.ExeDeptName.Trim();
                            attr05120.OrderAmount = (recipe.RecipeAmount * 100).ToString("#0");
                            list05120.Add(attr05120);

                        }

                        amount05120.OriginAmount = totalMoneyTemp05120.ToString("#0");
                        amount05120.TotalAmount = totalMoneyTemp05120.ToString("#0");
                        ((HIS_ATM_05120Body)body).Amount = amount05120;
                        ((HIS_ATM_05120Body)body).Extend = string.Empty;
                        ((HIS_ATM_05120Body)body).Orders = list05120;
                        break;
                    #endregion
                    #region 查询未缴费处方清单明细
                    case "HIS_ATM_05130":
                        //缴费编号
                        inputXMLdoc.Check("request/body/order/orderNo", false, out var orderNo05130);

                        if (!clinicService.GetUnPayRecipeList(callNo_DongRuan, callName_DongRuan, string.Empty, (string)orderNo05130, out IList<Recipe> recipeList05130))
                            throw new InvalidOperationException("未查询到相应的记录");
                        body = new HIS_ATM_05130Body();
                        List<HIS_ATM_05130Attr> list05130 = new List<HIS_ATM_05130Attr>();
                        foreach (Recipe recipe in recipeList05130)
                        {
                            HIS_ATM_05130Attr attr05130 = new HIS_ATM_05130Attr();
                            attr05130.ItemId = Convert.ToString(recipe.ItemId);
                            attr05130.ExecuteDept = recipe.ExeDeptName;
                            attr05130.ExecuteDeptAddr = null;
                            attr05130.ItemName = recipe.ItemName;
                            attr05130.Unit = recipe.Unit;
                            attr05130.Count = Convert.ToString(recipe.Quantity);
                            attr05130.Price = (recipe.Price * 100).ToString("#0");
                            attr05130.Amount = (recipe.Amount * 100).ToString("#0");
                            list05130.Add(attr05130);
                        }
                        ((HIS_ATM_05130Body)body).OrderItems = list05130;
                        break;
                    #endregion
                    #region 查询已缴费处方清单明细
                    case "HIS_ATM_05131":
                        //缴费编号
                        inputXMLdoc.Check("request/body/order/orderNo", false, out var orderNo05131);

                        IList<RecipePaid> recipeList05131 = clinicService.GetPaidRecipeList(callNo_DongRuan, callName_DongRuan, string.Empty, (string)orderNo05131);
                        if (recipeList05131.Count.Equals(0))
                            throw new InvalidOperationException("未查询到相应的记录");
                        body = new HIS_ATM_05130Body();
                        List<HIS_ATM_05130Attr> list05131 = new List<HIS_ATM_05130Attr>();
                        foreach (RecipePaid recipe in recipeList05131)
                        {
                            HIS_ATM_05130Attr attr05130 = new HIS_ATM_05130Attr();
                            attr05130.ItemId = Convert.ToString(recipe.ItemId);
                            attr05130.ExecuteDept = recipe.DeptName;
                            attr05130.ExecuteDeptAddr = null;
                            attr05130.ItemName = recipe.ItemName;
                            attr05130.Unit = recipe.Unit;
                            attr05130.Count = Convert.ToString(recipe.Num);
                            attr05130.Price = (recipe.Price * 100).ToString("#0");
                            attr05130.Amount = (recipe.RecipeAmount * 100).ToString("#0");
                            list05131.Add(attr05130);
                        }
                        ((HIS_ATM_05130Body)body).OrderItems = list05131;
                        break;
                    #endregion
                    #region 挂号费用记录
                    case "HIS_ATM_05200":
                        //病人Id
                        inputXMLdoc.Check("request/body/patient/patientId", false, out var patientId05200);
                        List<RegistPaymentRecords> payRecordList05200 = clinicService.GetRegistPayRecord(callNo_DongRuan, callName_DongRuan, (string)patientId05200);
                        if (payRecordList05200.Count.Equals(0))
                        {
                            throw new InvalidOperationException("未查询到相应的记录");
                        }
                        body = new HIS_ATM_05200Body();
                        List<HIS_ATM_05200Attr> list05200 = new List<HIS_ATM_05200Attr>();
                        foreach (RegistPaymentRecords record in payRecordList05200)
                        {
                            HIS_ATM_05200Attr attr05200 = new HIS_ATM_05200Attr();
                            attr05200.RegisterId = Convert.ToString(record.RegisterId).Trim();
                            attr05200.DeptName = record.DeptName.Trim();
                            attr05200.DoctorName = record.DoctorName.Trim();
                            attr05200.RegDateTime = Convert.ToString(record.RegDateTime).Trim();
                            attr05200.TotalAmount = (record.TotalAmount * 100).ToString("#0").Trim();
                            list05200.Add(attr05200);
                        }
                        ((HIS_ATM_05200Body)body).RegItems = list05200;
                        break;
                    #endregion
                    #region 查询已缴费处方清单
                    case "HIS_ATM_05121":
                        //门诊流水号
                        inputXMLdoc.Check("request/body/patient/clinicNo", false, out var clinicNo05121);
                        IList<RecipePaid> recipeList05121 = clinicService.GetPaidRecipeList(callNo_DongRuan, callName_DongRuan, (string)clinicNo05121, string.Empty);

                        if (recipeList05121.Count.Equals(0))
                            throw new InvalidOperationException("未查询到相应的记录");

                        body = new HIS_ATM_05121Body();
                        List<HIS_ATM_05121Attr> list05121 = new List<HIS_ATM_05121Attr>();
                        HIS_ATM_05121Amount amount05121 = new HIS_ATM_05121Amount();
                        amount05121.ClinicNo = (string)clinicNo05121;
                        decimal totalMoneyTemp05121 = 0;
                        //结果分组
                        var groupList05121 = recipeList05121.GroupBy(a => new { a.Recipeid, a.DeptName, a.ItemType, a.RecipeAmount })
                                                            .Select(b => new { b.Key.Recipeid, b.Key.DeptName, b.Key.ItemType, b.Key.RecipeAmount }).ToList();

                        foreach (var recipe in groupList05121)
                        {
                            //金额换算成分
                            totalMoneyTemp05121 = totalMoneyTemp05121 + (recipe.RecipeAmount * 100);
                            HIS_ATM_05121Attr attr05121 = new HIS_ATM_05121Attr();
                            attr05121.OrderNo = Convert.ToString(recipe.Recipeid);
                            attr05121.FeesItem = recipe.ItemType.Trim();
                            attr05121.DeptName = recipe.DeptName.Trim();
                            attr05121.OrderAmount = (recipe.RecipeAmount * 100).ToString("#0");
                            list05121.Add(attr05121);
                        }
                        amount05121.OriginAmount = totalMoneyTemp05121.ToString("#0");
                        amount05121.TotalAmount = totalMoneyTemp05121.ToString("#0");
                        ((HIS_ATM_05121Body)body).Extend = string.Empty;
                        ((HIS_ATM_05121Body)body).Amount = amount05121;
                        ((HIS_ATM_05121Body)body).Orders = list05121;
                        break;
                    #endregion
                    #region 充值记录查询
                    case "HIS_ATM_06200":
                        break;
                    #endregion
                    #region 费用对账(费用明对账明细)
                    case "HIS_ATM_09100":
                        break;
                    #endregion
                    #region 个人信息
                    case "HIS_ATM_10100":
                        break;
                    #endregion
                    #region 个人病例
                    case "HIS_ATM_10300":
                        break;
                    #endregion
                    #region 查询检验报告单
                    case "HIS_ATM_11100":
                        break;
                    case "HIS_ATM_11101":
                        //患者ID
                        inputXMLdoc.Check("request/body/patientId", false, out var patientId11100);

                        List<InspectReportCount> inspectRecords = reportService.GetInspectRecordByMZNum(callNo_DongRuan, callName_DongRuan, (string)patientId11100);
                        if (inspectRecords.Count.Equals(0))
                            throw new InvalidOperationException("没有相应的记录");
                        List<HIS_ATM_11101Attr> list11101 = new List<HIS_ATM_11101Attr>();
                        body = new HIS_ATM_11101Body();
                        inspectRecords.ForEach(c => list11101.Add(new HIS_ATM_11101Attr
                        {
                            PatientCode = c.PatientCode,
                            PatientName = c.PatientName,
                            TotleReport = c.TotleReport,
                            FinishReport = c.FinishReport,
                            PinrtReport = c.PrintReport
                        }));

                        ((HIS_ATM_11101Body)body).outPatients = list11101;
                        break;
                    #endregion
                    #region 查询检验报告单明细
                    case "HIS_ATM_11200":
                        //患者ID
                        inputXMLdoc.Check("request/body/patientId", false, out var patientId11200);
                        //报告编号
                        inputXMLdoc.Check("request/body/reportNo", false, out var reportNo11200);
                        //报告种类名称
                        inputXMLdoc.Check("request/body/reportKind", true, out var reportKind11200);

                        body = new HIS_ATM_11200Body();
                        ReportDetailLis reportLis = new ReportDetailLis();
                        reportLis.ReportNo = "报告编号";
                        reportLis.ReportCategory = "报告类型名称";
                        reportLis.ReportDate = "报告日期";
                        reportLis.CheckDate = "检验日期";
                        reportLis.BarCode = "条形码";
                        ((HIS_ATM_11200Body)body).ReportDetail = reportLis;
                        ((HIS_ATM_11200Body)body).ReportResource = "图片base64格式";

                        break;
                    #endregion
                    #region 查询检查报告单
                    case "HIS_ATM_11400":
                        //患者ID
                        inputXMLdoc.Check("request/body/patientId", false, out var patientId11400);
                        //打印状态
                        inputXMLdoc.Check("request/body/printStatus", false, out var printStatus11400, FieldType.Integer, printStatusDic);

                        body = new HIS_ATM_11400Body();
                        List<CheckReport> checkList11400 = reportService.GetCheckReport(callNo_DongRuan, callName_DongRuan, (string)patientId11400, (int)printStatus11400);
                        if (checkList11400.Count == 0)
                            throw new InvalidOperationException("未查找到报告");

                        List<HIS_ATM_11400Attr> list11400 = new List<HIS_ATM_11400Attr>();
                        foreach (CheckReport check in checkList11400)
                        {
                            HIS_ATM_11400Attr attr11400 = new HIS_ATM_11400Attr();
                            attr11400.ReportNo = Convert.ToString(check.ApplyNum);
                            attr11400.ReportDate = check.ReportDate.ToString();
                            attr11400.ReportKind = check.Type;
                            attr11400.ExaminNo = check.ApplyNum.ToString();
                            //if (check.PrnFlag.Equals(1))
                            //{
                            //    attr11400.PrintStatus = "1";
                            //}
                            //else
                            //{
                            //    attr11400.PrintStatus = "0";
                            //}
                            //if (check.State.Equals(0))
                            //{
                            //    attr11400.ReportStatus = "0";
                            //}
                            //else if (check.State.Equals(1))
                            //{
                            //    attr11400.ReportStatus = "0";
                            //}
                            //else if (check.State.Equals(2))
                            //{
                            //    attr11400.ReportStatus = "1";
                            //}
                            attr11400.PrintStatus = null;
                            list11400.Add(attr11400);
                        }
                        ((HIS_ATM_11400Body)body).Reports = list11400;
                        break;
                    #endregion
                    #region 查询检查报告单明细
                    case "HIS_ATM_11500":
                        //患者ID
                        inputXMLdoc.Check("request/body/patientId", false, out var patientId11500);
                        //报告编号
                        inputXMLdoc.Check("request/body/reportNo", false, out var reportNo11500);
                        //报告种类名称
                        inputXMLdoc.Check("request/body/examinNo", true, out var examinNo11500);

                        body = new HIS_ATM_11500Body();
                        List<CheckReport> checkList11500 = reportService.GetCheckReport(callNo_DongRuan, callName_DongRuan, (string)patientId11500, 2, (string)reportNo11500);
                        if (checkList11500.Count == 0)
                            throw new InvalidOperationException("未查找到报告");
                        ReportDetailPacks reportPacks = new ReportDetailPacks();
                        reportPacks.ReportNo = checkList11500[0].ApplyNum;
                        reportPacks.ReportKind = checkList11500[0].Type;
                        reportPacks.ReportDate = checkList11500[0].ReportDate;
                        reportPacks.ExaminNo = checkList11500[0].ApplyNum;
                        reportPacks.BarCode = string.Empty;
                        ((HIS_ATM_11500Body)body).ReportDetail = reportPacks;
                        //((HIS_ATM_11500Body)body).ReportResource = Convert.ToBase64String(checkList11500[0].Description);
                        ((HIS_ATM_11500Body)body).ReportResource = null;

                        break;
                    #endregion
                    #region 医保挂号登记申请
                    case "HIS_ATM_12110":
                        break;
                    #endregion
                    #region 医保挂号预结算解析
                    case "HIS_ATM_12120":
                        break;
                    #endregion
                    #region 医保挂号结算解析
                    case "HIS_ATM_12130":
                        break;
                    #endregion
                    #region 医保诊间缴费结算申请
                    case "HIS_ATM_12210":
                        break;
                    #endregion
                    #region 医保诊间缴费预结算解析
                    case "HIS_ATM_12220":
                        break;
                    #endregion
                    #region 医保诊间缴费结算解析
                    case "HIS_ATM_12230":
                        break;
                    #endregion
                    #region 医保入院登记申请
                    case "HIS_ATM_12310":
                        break;
                    #endregion
                    #region 医保入院登记解析
                    case "HIS_ATM_12320":
                        break;
                    #endregion
                    #region 医保出院结算申请
                    case "HIS_ATM_12410":
                        break;
                    #endregion
                    #region 医保出院结算解析
                    case "HIS_ATM_12420":
                        break;
                    #endregion
                    #region 医保撤销业务申请
                    case "HIS_ATM_12500":
                        break;
                    #endregion
                    #region 医保签到查询
                    case "HIS_ATM_12610":
                        break;
                    #endregion
                    #region 医保签到结果
                    case "HIS_ATM_12620":
                        break;
                    #endregion
                    #region 查询科室
                    case "HIS_ATM_13100":
                        inputXMLdoc.Check("request/body/currentTime", false, out var currentTime13100);
                        List<DepartmentInfo> deptList13100 = basicService.GetDeptInfo(callNo_DongRuan, callName_DongRuan);
                        if (deptList13100.Count.Equals(0))
                            throw new InvalidOperationException("未查询到相应的科室信息");
                        List<HIS_ATM_13100Attr> list13100 = new List<HIS_ATM_13100Attr>();
                        body = new HIS_ATM_13100Body();
                        foreach (DepartmentInfo list in deptList13100)
                        {
                            HIS_ATM_13100Attr _13100Attr = new HIS_ATM_13100Attr
                            {
                                DeptId = list.DeptCode,
                                DeptName = list.DeptName,
                                Address = list.Address
                            };
                            list13100.Add(_13100Attr);
                        }
                        ((HIS_ATM_13100Body)body).Depts = list13100;
                        break;
                    #endregion
                    #region 查询科室医生
                    case "HIS_ATM_13200":
                        inputXMLdoc.Check("request/body/deptCode", false, out var deptCode13200);
                        List<DoctInfo> doctList13200 = basicService.GetDoctInfo(callNo_DongRuan, callName_DongRuan, deptCode: (string)deptCode13200);
                        if (doctList13200.Count.Equals(0))
                            throw new InvalidOperationException("未查询到相应的医师信息");
                        List<HIS_ATM_13200Attr> list13200 = new List<HIS_ATM_13200Attr>();
                        body = new HIS_ATM_13200Body();
                        //筛选出医生
                        doctList13200.Where(a => a.DoctType.Equals(2)).ToList().ForEach(b => list13200.Add(new HIS_ATM_13200Attr
                        {
                            DoctorId = b.DoctCode.ToString(),
                            DoctName = b.DoctName.Trim(),
                            DeptCode = b.DeptCode.Trim(),
                            DeptName = b.DeptName.Trim(),
                            SessionType = b.SessionType
                        }));
                        ((HIS_ATM_13200Body)body).Orders = list13200;
                        break;
                    #endregion
                    #region 查询医生明细
                    case "HIS_ATM_13300":
                        inputXMLdoc.Check("request/body/doctorName", false, out var doctorName13300);
                        XmlNode node = inputXMLdoc.SelectSingleNode("request/body/doctorName");
                        List<DoctInfo> doctList13300 = basicService.GetDoctInfo(callNo_DongRuan, callName_DongRuan, (string)doctorName13300, null);
                        if (doctList13300.Count.Equals(0))
                            throw new InvalidOperationException("未查询到相应的医师信息");
                        List<HIS_ATM_13300Attr> list13300 = new List<HIS_ATM_13300Attr>();
                        body = new HIS_ATM_13300Body();
                        doctList13300.Where(a => a.DoctType.Equals(2)).ToList().ForEach(b => list13300.Add(new HIS_ATM_13300Attr
                        {
                            DoctName = b.DoctName.Trim(),
                            Sex = string.Empty,
                            DeptCode = b.DeptCode.Trim(),
                            DeptName = b.DeptName.Trim(),
                            SessionType = b.SessionType,
                            ManageOffice = b.IsMaster,
                            Expertintroduction = string.Empty
                        }));
                        ((HIS_ATM_13300Body)body).Orders = list13300;
                        break;
                    #endregion
                    #region 药品查询
                    case "HIS_ATM_13400":
                        //收费类别
                        inputXMLdoc.Check("request/body/feesItem", true, out var feesItem13400, FieldType.Integer, feesItemDic);
                        //药品助记码，模糊匹配药品名称拼音首字符
                        inputXMLdoc.Check("request/body/spelcode", true, out var spelcode13400);
                        string itemType;
                        switch (Convert.ToInt16(feesItem13400))
                        {
                            case 1:
                                itemType = "02";
                                break;
                            case 2:
                                itemType = "01";
                                break;
                            case 4:
                                itemType = "03";
                                break;
                            default:
                                itemType = "%";
                                break;

                        }
                        List<DrugInfo> drugList13400 = basicService.GetDrugInfo(callNo_DongRuan, callName_DongRuan, (string)spelcode13400, itemType);
                        if (drugList13400.Count.Equals(0))
                            throw new InvalidOperationException("未查询到相应的药品信息");
                        List<HIS_ATM_13400Attr> list13400 = new List<HIS_ATM_13400Attr>();
                        body = new HIS_ATM_13400Body();
                        drugList13400.ForEach(a => list13400.Add(new HIS_ATM_13400Attr
                        {
                            Drugname = a.GoodsName,
                            DrugSpec = a.GoodsTypeName,
                            OutpatientUnit = a.Unit,
                            OutpatientPrice = (a.UnitPrice * 100).ToString("#0"),
                            InpatientUnit = a.Unit,
                            InpatientPrice = (a.UnitPrice * 100).ToString("#0")
                        }));
                        ((HIS_ATM_13400Body)body).Items = list13400;
                        break;
                    #endregion
                    #region 收费项目查询(包含材料)
                    case "HIS_ATM_13500":
                        inputXMLdoc.Check("request/body/spelcode", true, out var spelcode13500);
                        List<CheckInfo> checkList13500 = basicService.GetCheckInfo(callNo_DongRuan, callName_DongRuan, (string)spelcode13500);
                        if (checkList13500.Count.Equals(0))
                            throw new InvalidOperationException("未查询到相应的项目");
                        List<HIS_ATM_13500Attr> list13500 = new List<HIS_ATM_13500Attr>();
                        body = new HIS_ATM_13500Body();
                        checkList13500.ForEach(checkInfo => list13500.Add(new HIS_ATM_13500Attr
                        {
                            ItemCode = checkInfo.ItemId,
                            ItemName = checkInfo.ItemName.Trim(),
                            Spec = checkInfo.ItemTypeName.Trim(),
                            Unit = checkInfo.ItemUnit,
                            Producingarea = string.Empty
                        }));
                        ((HIS_ATM_13500Body)body).Items = list13500;
                        break;
                    #endregion
                    #region 卫材价格查询
                    case "HIS_ATM_13600":
                        break;
                    #endregion
                    #region 查询患者住院信息
                    case "HIS_ATM_14100":
                        break;
                    #endregion
                    #region 出院结算申请
                    case "HIS_ATM_14300":
                        break;
                    #endregion
                    #region 出院结算费用明细
                    case "HIS_ATM_14400":
                        break;
                    #endregion
                    #region 住院费用记录明细
                    case "HIS_ATM_14600":
                        inputXMLdoc.Check("request/body/patientId", true, out var patientId14600);
                        List<InHospitalCostItem> inHospitalList = basicService.GetInHospitalCostItems(callNo_DongRuan, callName_DongRuan, (string)patientId14600);
                        if (inHospitalList.Count.Equals(0))
                            throw new InvalidOperationException("未查询到相应的住院信息");
                        List<HIS_ATM_14600Attr> list14600 = new List<HIS_ATM_14600Attr>();
                        body = new HIS_ATM_14600Body();
                        inHospitalList.ForEach(a => list14600.Add(new HIS_ATM_14600Attr
                        {
                            FeeDate = a.JZDate.ToString(),
                            ItemName = a.ItemName,
                            ItemNum = a.Num.ToString("#0"),
                            ItemPrice = (a.Price * 100).ToString("#0"),
                            ItemUnit = a.Unit,
                            ItemAmount = (a.YPMoney * 100).ToString("#0")
                        }));
                        ((HIS_ATM_14600Body)body).DeptName = inHospitalList[0].DeptName;
                        ((HIS_ATM_14600Body)body).Inday = inHospitalList[0].AdmissionDate.ToString();
                        ((HIS_ATM_14600Body)body).BedNo = inHospitalList[0].BedNo;
                        ((HIS_ATM_14600Body)body).MedicalId = inHospitalList[0].ZYNum;
                        ((HIS_ATM_14600Body)body).PrepayAmount = (inHospitalList[0].PreMoney * 100).ToString("#0");
                        ((HIS_ATM_14600Body)body).PrepayUsed = (inHospitalList[0].CostMoney * 100).ToString("#0");
                        ((HIS_ATM_14600Body)body).PrepayRemain = ((inHospitalList[0].PreMoney - inHospitalList[0].CostMoney) * 100).ToString("#0");
                        ((HIS_ATM_14600Body)body).Items = list14600;
                        break;
                    #endregion
                    #region 住院充值记录
                    case "HIS_ATM_14800":
                        break;
                        #endregion
                }
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                head.Code = "0";
                head.Error = errorMessage;
                body = null;
            }
            outputXML.Body = body;
            var resultXml = XmlHelper.Serializer(outputXML.GetType(), outputXML, arg1);
            log.Info(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "返回值: " + resultXml);
            return resultXml;
        }
    }
}